<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>网页简易音乐播放器</title>
</head>
<body>
<div id="app">
    <!--controls 如果声明了该属性，浏览器将提供一个包含声音，播放进度，播放暂停的控制面板，让用户可以控制音频的播放。-->
    <audio v-bind:src="music[currentIndex].songSrc" controls=""></audio>
    <ul>
        <li v-for="(item, index) in music" v-on:click="currentIndex = index">
            <h3>{{ item.id}}- 歌曲名称：{{ item.name }}</h3>
            <h4>歌手： {{ item.author }}</h4>
        </li>
    </ul>
</div>

<script type="module">
    import {createApp, reactive, ref} from "../../../js/vue.esm-browser.js";

    let app = createApp(
        {
            setup() {
                let music = reactive(
                    [
                        {
                            id: 1,
                            name: "不在犹豫",
                            author: "Beyond",
                            songSrc: "./static/不再犹豫.mp3"
                        },
                        {
                            id: 2,
                            name: "光辉岁月",
                            author: "Beyond",
                            songSrc: "./static/光辉岁月.mp3"
                        },

                        {
                            id: 3,
                            name: "海阔天空",
                            author: "Beyond",
                            songSrc: "./static/海阔天空.mp3"
                        },

                    ]
                )

                let currentIndex = ref(0)
                return {
                    music, currentIndex,
                }
            }
        }
    );

    app.mount("#app")
</script>
</body>
</html>